home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Utilities / Biomorph 0.77 / Complex src / complex.c next >
Encoding:
C/C++ Source or Header  |  1992-08-28  |  1.1 KB  |  52 lines  |  [TEXT/ALFA]

  1. /****************************************************
  2. *                                                   *
  3. * File:  complex.c -- routines for complex numbers. *
  4. *                                                   *
  5. ****************************************************/
  6.  
  7. #include "complex.h"
  8.  
  9. #define ar A->r       /* just to make math translation easier... */
  10. #define ai A->i
  11. #define br B->r
  12. #define bi B->i
  13.  
  14. void AddC(ImagPt *A, ImagPt *B, ImagPt *result)
  15. {
  16.     result->r = ar + br;
  17.     result->i = ai + bi;
  18.     result->mag = result->i * result->i + result->r * result->r;
  19.     return;
  20. }
  21.  
  22. void SubC(ImagPt *A, ImagPt *B, ImagPt *result)  /* returns A-B */
  23. {
  24.     result->r = ar -br;
  25.     result->i = ai-bi;
  26.     result->mag = result->i*result->i + result->r * result->r;
  27.     return;
  28. }
  29.  
  30. void MultC(ImagPt *A, ImagPt *B, ImagPt *result)
  31. {
  32.     result ->r = (ar * br) - (ai * bi);
  33.     result->i  = (ar * bi) + (br * ai);
  34.     result->mag = result->i*result->i + result->r * result->r;
  35.     return;
  36. }
  37.  
  38. void SquareC(ImagPt *A, ImagPt *result)
  39. {
  40.     MultC( A, A, result);
  41.     return;
  42. }
  43.  
  44. void CubeC(ImagPt *A, ImagPt *result)
  45. {
  46.     ImagPt temp;
  47.     
  48.     MultC( A, A, &temp);
  49.     MultC( A, &temp, result);
  50.     return;
  51. }
  52.